package test.yzx.pproject.act1;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import test.yzx.pproject.R;

public class Transition4Layout extends AppCompatActivity {

    private View block;
    private View text;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.t4);
        block = findViewById(R.id.block);
        text = findViewById(R.id.text);

        setAfterBounds();

        getWindow().getDecorView().postDelayed(new Runnable() {
            @Override
            public void run() {
                goTransition();
            }
        },1200);


    }


    private void setAfterBounds(){
        block.post(new Runnable() {
            @Override
            public void run() {
                float afterLen = 150 * 3;
                int afterScreenY = (getScreenHeight() - (int)afterLen ) / 2;
                int afterScreenX = getScreenWidth()/2 - (int)afterLen/2;

                block.setScaleX(afterLen / block.getWidth());
                block.setScaleY(afterLen / block.getHeight());
                int[] position = new int[2];
                block.getLocationOnScreen(position);
                block.setTranslationY(afterScreenY - position[1]);
                block.setTranslationX(afterScreenX - position[0]);
            }
        });


    }

    private void goTransition(){
       // ViewAnimatorUtil.goBoundsTogether(block, 600, 0, new DecelerateInterpolator(0.7f), 0f, 0f, 1f, 1f, null, null, null, null, null);
    }

    private int getScreenHeight(){
        return getResources().getDisplayMetrics().heightPixels;
    }
    private int getScreenWidth(){
        return getResources().getDisplayMetrics().widthPixels;
    }

}
